<template>
  <a-card>
    <p style="fontSize: 14px;color: rgba(0, 0, 0, 0.85); marginBottom: 16px;fontWeight: 1000">
      商户账户
      <a-icon type="eye-invisible" />
    </p>
    <div style="background-color: #ececec; padding: 20px;">
      <a-row :gutter="16">
        <a-col :span="8">
          <a-card title="总金额" :bordered="false">
            <p>￥{{allmoney_amount}}</p>
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="可用金额" :bordered="false">
            <p>￥{{available_amount}} <a-button type="primary" @click="fundWithDraw">提现</a-button></p>
          
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="冻结资金" :bordered="false">
            <p>￥{{pending_amount}}</p>
          </a-card>
        </a-col>
      </a-row>
    </div>
  </a-card>
</template>
<script>
import qs from "qs";
export default {
data () {
 return {
   //可用金额
     available_amount:0,
    //不可用金额
     pending_amount:0,
     allmoney_amount:0
 }
 },
 
 methods: {

   //获取账户金额
     getCash() {
    
      this.axios
        .post(
          "https://xh.bearing.cn/api/wxpay/fundBalanceQuery.php",
          qs.stringify({
            sub_mchid: this.$store.state.bbl_sub_mchid
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.allmoney_amount =
               (res.data.result.available_amount+res.data.result.pending_amount) / 100;
            //可用资金
            this.available_amount =
               res.data.result.available_amount / 100;
              //冻结资金
            this.pending_amount = res.data.result.pending_amount / 100;
      
        
          } else {
            
          }
        });
    },


    
    //调用提现接口
    fundWithDraw() {
      this.axios
        .post(
          "https://xh.bearing.cn/api/wxpay/fundwithdraw.php",
          qs.stringify({
            //二级商户号
            sub_mchid: this.$store.state.bbl_sub_mchid,
            //提取金额
            amount: this.available_amount*100
          })
        )
        .then(res => {
          if (res.data.code == 303) {
            this.available_amount = 0;
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
   
 },

 created () {
    
      console.log('sssssssssssssssss');
    //获取账户金额
    this.getCash()
 }
}
</script>